/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package three2learn.Controller;

import javax.servlet.http.HttpServlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import three2learn.Model.Student;
import three2learn.service.HibernateUtil;

/**
 *
 * @author Robbert
 */
public class StudentController extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction trans = session.beginTransaction();
        List<Student> studentenLijst = session.createQuery("from Student").list();

        request.setAttribute("studentenUitSessie", studentenLijst);
        request.setAttribute("aantalStudenten", studentenLijst.size());

        String address = "/registerStudent.jsp";
        RequestDispatcher dispatcher = request.getRequestDispatcher(address);
        dispatcher.forward(request, response);
        trans.commit();
    }
}
